package service;

import util.RegexUtil;
import dao.ActorDAO;
import dao.UserDAO;
import domain.Actor;
import domain.User;
import ex.AuthenticationFailedException;
import ex.DatabaseException;
import ex.RegistrationFailedException;

public class ActorService {

	ActorDAO actorDao=new ActorDAO();
	public Actor getActorByUid(long uid) throws DatabaseException{
		return actorDao.selectActorByUid(uid);
	}
	public void createActor(Actor actor) throws RegistrationFailedException, DatabaseException{
		if(actor!=null){
			if(RegexUtil.isNullOrEmpty(actor.getHairColor())){
				throw new RegistrationFailedException("You must enter hair color!");
			}
			if(RegexUtil.isNullOrEmpty(actor.getEyeColor())){
				throw new RegistrationFailedException("You must enter eye color!");
			}
			if(RegexUtil.isNullOrEmpty(actor.getSkinColor())){
				throw new RegistrationFailedException("You must enter skin color!");
			}
			if(actor.getHeight()==0){
				throw new RegistrationFailedException("You must enter height!");
			}
			if(actor.getWeight()==0){
				throw new RegistrationFailedException("You must enter weight!");
			}
			actorDao.insertActor(actor);
		}
		else{
			throw new RegistrationFailedException("Registration failed!");
		}		
	}
	public void deleteActor(Actor actor) throws DatabaseException{
		if(actor!=null){
			actorDao.deleteActor(actor);
		}
	}
	public void updateActor(Actor actor) throws RegistrationFailedException, DatabaseException {
		if(actor!=null){
			if(RegexUtil.isNullOrEmpty(actor.getHairColor())){
				throw new RegistrationFailedException("You must enter hair color!");
			}
			if(RegexUtil.isNullOrEmpty(actor.getEyeColor())){
				throw new RegistrationFailedException("You must enter eye color!");
			}
			if(RegexUtil.isNullOrEmpty(actor.getSkinColor())){
				throw new RegistrationFailedException("You must enter skin color!");
			}
			if(actor.getHeight()==0){
				throw new RegistrationFailedException("You must enter height!");
			}
			if(actor.getWeight()==0){
				throw new RegistrationFailedException("You must enter weight!");
			}
			actorDao.editActor(actor);
		}
		else{
			throw new RegistrationFailedException("Update failed!");
		}		
	}
}
